package com.sgb.kjwl.view.ui.activity.transport.owner;

import android.content.Intent;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.sgb.capital.callback.Constants;
import com.sgb.capital.callback.ZMessageEvent;
import com.sgb.capital.model.PayInfoEntity;
import com.sgb.capital.model.QRcodeEntity;
import com.sgb.capital.view.ui.activity.BusinessManagementActivity;
import com.sgb.capital.view.ui.activity.PersonPayActivity;
import com.sgb.capital.view.ui.activity.QrCodeActivity;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityTransportOrderDetailsBinding;
import com.sgb.kjwl.model.entity.transport.OperateGoodsSourcePlaceVO;
import com.sgb.kjwl.model.entity.transport.SingleItemConstant;
import com.sgb.kjwl.model.entity.transport.SingleItemEntity;
import com.sgb.kjwl.model.entity.transport.TransportOrderEntity;
import com.sgb.kjwl.model.entity.transport.common.AddressItem;
import com.sgb.kjwl.utils.CargoConstant;
import com.sgb.kjwl.view.event.LogisticsEvent;
import com.sgb.kjwl.view.ui.activity.self.order.OrderRequireInfoActivity;
import com.sgb.kjwl.view.ui.activity.transport.DepartureCertificateActivity;
import com.sgb.kjwl.view.ui.activity.transport.FreightPaymentVoucherActivity;
import com.sgb.kjwl.view.ui.activity.transport.LoadingAndUnloadingPlaceActivity;
import com.sgb.kjwl.view.ui.activity.transport.OfflineCollectionConfirmActivity;
import com.sgb.kjwl.view.ui.activity.transport.ReceiptCertificateActivity;
import com.sgb.kjwl.view.ui.activity.transport.SureStartTransportActivity;
import com.sgb.kjwl.view.ui.activity.transport.TrackDetailDiagramActivity;
import com.sgb.kjwl.view.ui.activity.transport.TransportInvoiceInfoActivity;
import com.sgb.kjwl.view.ui.adapter.transport.OrderGoodsInfoAdapter;
import com.sgb.kjwl.view.ui.adapter.transport.TransportInfoAdapter;
import com.sgb.kjwl.view.ui.adapter.transport.TransportOrderDetailAddressAdapter;
import com.sgb.kjwl.view.widget.WrapLinearLayout;
import com.sgb.kjwl.view.widget.transport.CarListBottomDialog;
import com.sgb.kjwl.view.widget.transport.InvoiceInfoBottomDialog;
import com.sgb.kjwl.viewmodel.transport.TransportOrderDetailModel;
import com.sgb.link.view.widget.ExpandedTextView;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.event.EventConstant;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.NumberUtil;
import com.swgk.core.util.UserOperating;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Time:2021/2/3
 * Author:黄淋
 * Description:运输订单详情
 */
public class TransportOrderDetailOwnerActivity extends AppActivity implements TransportOrderDetailAddressAdapter.ItemOnClickListen, ItemInputTextView.OnWholeItemClickListener {
    private ActivityTransportOrderDetailsBinding mBinding;
    TransportInfoAdapter mAdapter;
    List<String> mListString;//货源信息
    TransportOrderDetailAddressAdapter transportOrderDetailAddressAdapter;//运输订单详情地址

    TransportOrderDetailModel viewModel;
    Bundle savedInstanceState;
    String mOrderNo;//订单编号
    int isGoodsOwner;//是否是货主   1是货主  0是车主

    public static int GOODS_OWNER = 1;//货主
    public static int CAR_OWNER = 0;//车主

    private Map mMap;

    TransportOrderEntity mEntity;
    private boolean mIsExpanded = false;//订单信息是否展开
    private List<String> mListDepartureImg;//发车凭证
    private List<String> mListReceiveImg;//收货凭证
    private List<String> mListPayImg;//收货凭证
    private static final int REQUEST_CODE_REFRESH = 3;
    List mListDepartureImgNew;
    List mListReceiveImgNew;
    boolean mIsHasFrieght = false;
    //是否需要展示物流地图
    boolean isViewTrack = false;

    private AMap aMap;    //地图控制器
    private MapView mapView;    //高德3DMap  地图显示View

    //订单是否包含信息费
    private boolean isHaveMsgCost = false;
    //自定义字段列表
    private List<SingleItemEntity> mCustomList;
    private OrderGoodsInfoAdapter mCustomAdapter;
    private PayTimer mPayTimer;

    private InvoiceInfoBottomDialog invoiceDialog;
    private CarListBottomDialog carInfoWindow;

    //信息费支付超时弹窗是否已弹起
    private boolean isTimeoutShowed = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.savedInstanceState = savedInstanceState;
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().post(LogisticsEvent.make().setMessageTag(EventConstant.EVENT_ORDER_DETAIL_REFRESH));
        EventBus.getDefault().unregister(this);
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        if (mapView != null)
            mapView.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        if (mapView != null)
            mapView.onPause();
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，
        //保存地图当前的状态
        if (mapView != null)
            mapView.onSaveInstanceState(outState);
    }

    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_transport_order_details);
        //scrollview 和 Map嵌套产生的滑动冲突解决
        mBinding.mapContainer.setScrollView(mBinding.scrollView);
        mapView = mBinding.map;
        viewModel = new ViewModelProvider(this).get(TransportOrderDetailModel.class);
        initMap();
        mBinding.scrollView.setVisibility(View.GONE);
        mBinding.actionBar.setOnBackClickListener(view -> finish());
        //司机位置跳转
        mBinding.location.setOnClickListener(view -> {
            if (mEntity != null && mEntity.getLongitude() != 0 && mEntity.getLatitude() != 0)
                TransportDriverLocationActivity.start(this, mEntity);
        });
        initEvents();
        mBinding.rvGoodsInfo.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false));
        mAdapter = new TransportInfoAdapter(this, null);
        mBinding.rvGoodsInfo.setAdapter(mAdapter);
        mListString = new ArrayList<>();
        mListDepartureImg = new ArrayList<>();
        mListReceiveImg = new ArrayList<>();
        mOrderNo = getIntent().getStringExtra("no");
        isGoodsOwner = getIntent().getIntExtra("isGoodsOwner", GOODS_OWNER);
    }

    private void initEvents() {
        mBinding.setOnClick(this::onClick);
        mBinding.itvPaymentAppointment.setOnWholeItemClickListener(this);
        mBinding.itvRequirement.setOnWholeItemClickListener(this);

        viewModel.ldDetails.observe(this, this::setData);
        viewModel.ldSureOrder.observe(this, string -> sureOrderSuccess());
        viewModel.ldMapLoadFinish.observe(this, aBoolean -> viewMap());

        viewModel.ldTradeNoFreight.observe(TransportOrderDetailOwnerActivity.this, infoEntity -> {
            if (mEntity.getTerminal() == 1) {
//                订单列表和订单详情企业支付运费跳待付订单
                BusinessManagementActivity.start(TransportOrderDetailOwnerActivity.this, 1);
            } else {
                //团队  进资金中心
                if ("".equals(infoEntity.getTradeNo())) {
                    return;
                }
                PayInfoEntity paymentEntity = new PayInfoEntity();
                paymentEntity.amount = Double.valueOf(mEntity.getAllFreight());
                paymentEntity.tradeNo = infoEntity.getTradeNo();
                paymentEntity.orderId = infoEntity.getFreightOrderNo();
                PersonPayActivity.start(TransportOrderDetailOwnerActivity.this, infoEntity.getFreightOrderNo());
            }
        });
        viewModel.ldTimeout.observe(this, aBoolean -> {
            if (aBoolean != null && aBoolean) {
                showTimeoutDialog();
            }
        });
    }

    private void initMap() {
        mapView.onCreate(savedInstanceState);
        aMap = mapView.getMap();
        UiSettings uiSettings = aMap.getUiSettings();//地图的UI设置控制器
        uiSettings.setAllGesturesEnabled(true);//关闭一切手势操作
        uiSettings.setCompassEnabled(false);// 设置指南针是否显示
        uiSettings.setZoomControlsEnabled(false);// 设置缩放按钮是否显示
        uiSettings.setScaleControlsEnabled(false);// 设置比例尺是否显示
        uiSettings.setRotateGesturesEnabled(false);// 设置地图旋转是否可用
        uiSettings.setTiltGesturesEnabled(false);// 设置地图倾斜是否可用
        uiSettings.setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
    }

    private void viewMap() {
        if (isViewTrack) {
            mBinding.mapLayout.setVisibility(View.VISIBLE);
        } else {
            mBinding.mapLayout.setVisibility(View.GONE);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        mMap = new HashMap();
        mMap.put("orderNo", mOrderNo);
        mMap.put("isGoodsOwner", isGoodsOwner);
        viewModel.getDetailData(this, mMap);
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        if (mapView != null)
            mapView.onResume();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.invoice_info_view://查看开票信息
                if (mEntity == null)
                    return;
                if (invoiceDialog == null) {
                    invoiceDialog = new InvoiceInfoBottomDialog(getActivity(), null);
                }
                invoiceDialog.show();
                InvoiceInfoBottomDialog.InvoiceInfo invoiceInfo = new InvoiceInfoBottomDialog.InvoiceInfo(mEntity.getInvoicingCompanyName(),
                        mEntity.getInvoicingTaxNumber(), mEntity.getInvoicingAddress(), mEntity.getInvoicingCompanyPhone(),
                        mEntity.getInvoicingBank(), mEntity.getInvoicingBankAccount(), mEntity.getInvoicingBankNumber());
                invoiceDialog.setInvoiceInfo(invoiceInfo);
                break;

            case R.id.carrier_cars_view://查看承运车辆
                if (mEntity != null && mEntity.getDriverAuths() != null && mEntity.getDriverAuths().size() > 0) {
                    if (carInfoWindow == null) {
                        carInfoWindow = new CarListBottomDialog(this, mEntity.getDriverAuths());
                    }
                    carInfoWindow.show();
                }
                break;

            case R.id.view_logistics_details:
                TrackDetailDiagramActivity.start(this, mOrderNo, mEntity);
                break;

            case R.id.tv_online://在线联系
                if (mEntity != null)
                    // TODO IM功能目前需要全部去掉，此处需要后期IM迁移完成后完善
                    if (isGoodsOwner == GOODS_OWNER && !TextUtils.isEmpty(mEntity.getDriverOwnerImAccount())) {
                        buildSingleTalking(mEntity.getDriverOwnerImAccount());
                    } else if (isGoodsOwner == CAR_OWNER && !TextUtils.isEmpty(mEntity.getGoodsOwnerImAccount())) {
                        buildSingleTalking(mEntity.getGoodsOwnerImAccount());
                    }
                break;
            case R.id.phone://只有货主方可打电话给承运方
                if (mEntity != null && isGoodsOwner == GOODS_OWNER && !TextUtils.isEmpty(mEntity.getTelPhoneNum())) {
                    showTelDialog(mEntity.getTelPhoneNum());
                }
                break;
            case R.id.carrier_group_phone:
                if (mEntity != null && isGoodsOwner == GOODS_OWNER && !TextUtils.isEmpty(mEntity.getContrctsNumber())) {
                    showTelDialog(mEntity.getContrctsNumber());
                }
                break;
            case R.id.tv_call_contact://拨打电话
                if (mEntity != null)
                    if (isGoodsOwner == GOODS_OWNER && !TextUtils.isEmpty(mEntity.getTelPhoneNum())) {
                        showTelDialog(mEntity.getTelPhoneNum());
                    } else if (isGoodsOwner == CAR_OWNER && !TextUtils.isEmpty(mEntity.getGoodsOwnerPhone())) {
                        showTelDialog(mEntity.getGoodsOwnerPhone());
                    }
                break;
            case R.id.title2_content://发货电话
                if (mEntity != null && !TextUtils.isEmpty(mEntity.getSendPhone())) {
                    showTelDialog(mEntity.sendPhone);
                }
                break;
            case R.id.title2_receive_content://收货电话
                if (mEntity != null && !TextUtils.isEmpty(mEntity.getReceptionPhone())) {
                    showTelDialog(mEntity.receptionPhone);
                }
                break;
            case R.id.tv_start_picture://发车凭证
                if (mEntity != null && mListDepartureImgNew != null && mListDepartureImgNew.size() > 0) {
                    DepartureCertificateActivity.start(this, mListDepartureImgNew, false);
                }
                break;
            case R.id.tv_receive_picture://收货凭证0
                if (mEntity != null && mListReceiveImgNew != null && mListReceiveImgNew.size() > 0) {
                    ReceiptCertificateActivity.start(this, mListReceiveImgNew);
                }
                break;
            case R.id.pay_proof://支付凭证
                if (mEntity != null && mListPayImg != null && mListPayImg.size() > 0) {
                    FreightPaymentVoucherActivity.start(this, mListPayImg);
                }
                break;
            case R.id.tv_unfold_more:
            case R.id.iv_unfold:
                if (mIsExpanded) {
                    mBinding.llOrderMoreDetail.setVisibility(View.GONE);
                    mBinding.ivUnfold.setImageResource(R.mipmap.btn_expand1);
                    mBinding.tvUnfoldMore.setText("展开更多");
                    mIsExpanded = false;
                } else {
                    mBinding.llOrderMoreDetail.setVisibility(View.VISIBLE);
                    mBinding.ivUnfold.setImageResource(R.mipmap.btn_expand_up_gray);
                    mBinding.tvUnfoldMore.setText("收起更多");
                    mIsExpanded = true;
                }
                break;
            case R.id.tv_confirm_receive://确认
                switch (mBinding.tvConfirmReceive.getText().toString()) {
                    case "确认发车"://车主-待发车
                        if (mEntity != null) {
                            if (mEntity.getMessagePrice().equals("") || mEntity.getMessagePrice().equals("0元")) {
                                SureStartTransportActivity.start(this, mOrderNo, SureStartTransportActivity.START_TRANSPORT);
                            } else {
                                SureStartTransportActivity.start(this, mOrderNo, SureStartTransportActivity.START_TRANSPORT_UN_INFOPRICE, mEntity.messagePrice);
                            }
                        }
                        break;

                    case "确认送达"://车主-运输中
                        SureStartTransportActivity.start(this, mOrderNo, SureStartTransportActivity.ARRIVED, mEntity.allFreight);
                        break;

                    case "收款二维码"://车主-待支付
                        viewModel.getPayFreight(TransportOrderDetailOwnerActivity.this, mOrderNo);
                        viewModel.ldTradeNo.observe(TransportOrderDetailOwnerActivity.this, info -> {
                            if ("".equals(info.getFreightOrderNo())) {
                                return;
                            }
                            QRcodeEntity qRcodeEntity = new QRcodeEntity();
                            qRcodeEntity.amount = info.getAmount() + "";
                            qRcodeEntity.orderId = info.getFreightOrderNo();
                            qRcodeEntity.payType = "WX";
                            String json = new Gson().toJson(qRcodeEntity);
                            QrCodeActivity.start(getActivity(), json);

                        });
                        break;

                    case "支付运费"://货主-待支付
                        if (mEntity != null && mEntity.getPlace() != null) {
                            new RoundDialog.Builder(this)
                                    .title("提示")
                                    .content("由 " + mEntity.getPlace().getCityName() + " " + mEntity.getPlace().getDistrictName() + " " + "→" + " " + mEntity.getPlace().getDestCityName() + " " + mEntity.getPlace().getDestDistrictName() + "的待支付运费为" + mEntity.getAllFreight() + "元，您确定要支付该笔运费吗？")
                                    .cancel("取消")
                                    .confirm("确定")
                                    .contentGravity(Gravity.CENTER)
                                    .cancelable(false)
                                    .confirmCallback(v1 -> {
                                        viewModel.getPayFreightInfo(TransportOrderDetailOwnerActivity.this, mOrderNo);
                                    }).show();
                        }
                        break;
                    case "确认订单"://货主-待确认
                        new RoundDialog.Builder(this)
                                .title("提示")
                                .content("您确定由" + mEntity.getCarNumber() + "的车主" + mEntity.getUserName() + "运输货物吗？")
                                .confirm("确定")
                                .cancelable(false)
                                .confirmCallback(view -> {
                                    viewModel.getSureOrder(this, mOrderNo);
                                })
                                .show();
                        break;

                    case "支付信息费":
                        // 团队和个人去支付信息费
                        toPayMsgFee();
                        break;
                }
                break;

            case R.id.tv_offline_collection:
                if (mEntity != null && !TextUtils.isEmpty(mEntity.getAllFreight()))
                    OfflineCollectionConfirmActivity.start(this, mOrderNo, mEntity.getAllFreight());
                break;
        }
    }


    /**
     * 支付信息费
     */
    private void toPayMsgFee() {
        if (mEntity != null && !TextUtils.isEmpty(mEntity.getMessageOrderNo()))
            PersonPayActivity.start(this, mEntity.getMessageOrderNo());
    }

    /**
     * 确认订单成功
     */
    public void sureOrderSuccess() {
        EventBus.getDefault().post(LogisticsEvent.make().setMessageTag(EventConstant.EVENT_ORDER_DETAIL_REFRESH));
        MToast.showToast(this, "操作成功");
        viewModel.getDetailData(this, mMap);
    }

    private void showTelDialog(String phone) {
        new RoundDialog.Builder(this)
                .title("确认拨号")
                .content(phone)
                .confirm("拨打")
                .cancelable(false)
                .confirmCallback(v -> {
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    Uri data = Uri.parse("tel:" + phone);
                    intent.setData(data);
                    startActivity(intent);
                })
                .show();
    }


    public void setData(TransportOrderEntity entity) {
        if (null != entity) {
            this.mEntity = entity;
            mBinding.scrollView.setVisibility(View.VISIBLE);
            mBinding.flBtn.setVisibility(View.VISIBLE);
            mBinding.setViewModel(entity);

            if (entity.getMessagePrice().equals("") || entity.getMessagePrice().equals("0元")) {
                isHaveMsgCost = false;
                mBinding.tvMessagePayState.setVisibility(View.GONE);
                mBinding.tvMessage.setVisibility(View.GONE);
                mBinding.tvMessageInfo.setVisibility(View.GONE);
                mBinding.countDownLayout.setVisibility(View.GONE);
            } else {
                isHaveMsgCost = true;
                mBinding.tvMessagePayState.setVisibility(View.VISIBLE);
                mBinding.tvMessage.setVisibility(View.VISIBLE);
                mBinding.tvMessageInfo.setVisibility(View.VISIBLE);
            }

            //信息费支付中显示支付倒计时
            if (mEntity.getStatus() != null && mEntity.getStatus() == 0) {
                if (mEntity.getPaymentEndTime() != null && mEntity.getSystemTime() != null && mEntity.getPaymentEndTime() > mEntity.getSystemTime()) {//支付时间未过期
                    if (mPayTimer != null)
                        mPayTimer.cancel();
                    mPayTimer = new PayTimer(mEntity.getPaymentEndTime() - mEntity.getSystemTime(), 1000);
                    mBinding.countDownLayout.setVisibility(View.VISIBLE);
                    mPayTimer.start();
                } else {
                    mBinding.countDownLayout.setVisibility(View.GONE);
                    viewModel.ldTimeout.postValue(true);
                }
            } else {
                mBinding.countDownLayout.setVisibility(View.GONE);
            }
            //显示多个自定义字段
            if (mEntity.getAddField() != null && mEntity.getAddField().size() > 0) {
                mCustomList = new ArrayList<>();
                mCustomList = getCustomList(mEntity);
                mCustomAdapter = new OrderGoodsInfoAdapter(mCustomList, false);
                mBinding.newFieldList.setLayoutManager(new LinearLayoutManager(this));
                mCustomAdapter.bindToRecyclerView(mBinding.newFieldList);
                mBinding.newFieldList.setVisibility(View.VISIBLE);
            } else {
                mBinding.newFieldList.setVisibility(View.GONE);
            }

            //不同身份的显示逻辑处理
            if (entity.getQuoteOfferType() != null) {
                if (entity.getQuoteOfferType() == 1 || entity.getQuoteOfferType() == 2) {//企业团队
                    mBinding.carrierGroupInfoLayout.setVisibility(View.VISIBLE);
                    mBinding.carrierPersonalInfoLayout.setVisibility(View.GONE);
                    //承运车辆信息
                    boolean isShowCarInfo = false;
                    //承运车辆展示逻辑修改，企业和团队可展示多辆，没有不展示
                    if (entity.getDriverAuths() != null && entity.getDriverAuths().size() > 0) {
                        int carNum = 0;
                        String carInfo = "";
                        for (int i = 0; i < entity.getDriverAuths().size(); i++) {
                            if (entity.getDriverAuths().get(i) != null && !TextUtils.isEmpty(entity.getDriverAuths().get(i).getCarNumber())) {
                                carNum++;
                                if (carNum == 1) {
                                    carInfo += entity.getDriverAuths().get(i).getCarNumber() + "  ";
                                } else if (carNum == 2) {
                                    carInfo += entity.getDriverAuths().get(i).getCarNumber();
                                    break;
                                }
                            }
                        }
                        if (!TextUtils.isEmpty(carInfo)) {
                            mBinding.carrierCarsContent.setText(carInfo);
                            isShowCarInfo = true;
                        }
                    }
                    if (isShowCarInfo) {
                        mBinding.carrierCarsContent.setVisibility(View.VISIBLE);
                        mBinding.carrierCarsTv.setVisibility(View.VISIBLE);
                        mBinding.carrierCarsView.setVisibility(View.VISIBLE);
                    } else {
                        mBinding.carrierCarsContent.setVisibility(View.GONE);
                        mBinding.carrierCarsTv.setVisibility(View.GONE);
                        mBinding.carrierCarsView.setVisibility(View.GONE);
                    }

                    mBinding.groupAddressContent.setText(!TextUtils.isEmpty(mEntity.getDetailAddress()) ? mEntity.getDetailAddress() : "/");

                    mBinding.carrierGroupName.setText(entity.getCarrierGroupName());
                    if (!TextUtils.isEmpty(entity.getContrctsNumber())) {
                        mBinding.carrierGroupPhone.setText(entity.getContrctsNumber());
                        mBinding.carrierGroupPhone.setVisibility(View.VISIBLE);
                    } else {
                        mBinding.carrierGroupPhone.setVisibility(View.GONE);
                    }

                    //开票信息
                    if (entity.isNeedShowInvoiceInfo()) {
                        mBinding.invoiceInfoContentLayout.setVisibility(View.VISIBLE);
                        mBinding.invoiceInfoTv.setVisibility(View.VISIBLE);
                        mBinding.invoiceInfoContent.setText(entity.getInvoicingCompanyName());
                    } else {
                        mBinding.invoiceInfoContentLayout.setVisibility(View.GONE);
                        mBinding.invoiceInfoTv.setVisibility(View.GONE);
                    }

                } else if (entity.getQuoteOfferType() == 3) {//个人
                    mBinding.carrierGroupInfoLayout.setVisibility(View.GONE);
                    mBinding.carrierPersonalInfoLayout.setVisibility(View.VISIBLE);

                    mBinding.name.setText(entity.getUserName());
                    if (!TextUtils.isEmpty(mEntity.getTelPhoneNum())) {
                        if (!TextUtils.isEmpty(entity.getUserName())) {
                            mBinding.phone.setText("     " + entity.getTelPhoneNum());
                        } else {
                            mBinding.phone.setText(entity.getTelPhoneNum());
                        }
                        mBinding.phone.setText(entity.getTelPhoneNum());
                        mBinding.phone.setVisibility(View.VISIBLE);
                    } else {
                        mBinding.phone.setVisibility(View.GONE);
                    }
                    mBinding.carAgeValue.setText(entity.getCarAge());
                    mBinding.carDriveAgeValue.setText(entity.getDriverAge());

                    StringBuilder builder = new StringBuilder();
                    if (entity.getCarNumber() != null && !entity.getCarNumber().isEmpty()) {
                        builder.append(entity.getCarNumber()).append(" ");
                    }
                    if (entity.getCarTypeName() != null && !entity.getCarTypeName().isEmpty()) {
                        builder.append(entity.getCarTypeName());
                    }
                    if (entity.getCarLenName() != null && !entity.getCarLenName().isEmpty() && !entity.getHeightHurdle().equals("0米")) {
                        builder.append("/长").append(entity.getCarLenName());
                    }
                    if (entity.getCarWeight() != null && !entity.getCarWeight().isEmpty() && !entity.getCarWeight().equals("0")) {
                        builder.append("/额定载重").append(entity.getCarWeight()).append("吨");
                    }
                    if (entity.getHeightHurdle() != null && !entity.getHeightHurdle().isEmpty() && !entity.getHeightHurdle().equals("0")) {
                        builder.append("/栏高").append(entity.getHeightHurdle()).append("米");
                    }
                    if (entity.getFunctionNos() != null && !entity.getFunctionNos().isEmpty()) {
                        builder.append("/").append(entity.getFunctionNos());
                    }
                    mBinding.carInfo.setText(builder.toString().isEmpty() ? "/" : builder.toString());

                    mBinding.tvCarLocation.setText((entity.getProvinceName() + entity.getCityName() + entity.getDistrictName() + entity.getDetailAddress()).isEmpty() ?
                            "/" : (entity.getProvinceName() + entity.getCityName() + entity.getDistrictName() + entity.getDetailAddress()));
                }
            }

            //预计到场时间
            if (entity.getInTime() != null) {
                mBinding.predictArriveTime.setText(DateUtils.timestampTo13DateNos(entity.getInTime()));
                mBinding.predictArriveTimeLayout.setVisibility(View.VISIBLE);
            } else {
                mBinding.predictArriveTime.setText("/");
                mBinding.predictArriveTimeLayout.setVisibility(View.GONE);
            }

            //备注
            if (!TextUtils.isEmpty(entity.getNote())) {
                mBinding.noteLayout.setVisibility(View.VISIBLE);
                mBinding.noteTv.setText(entity.getNote());
                new ExpandedTextView().showTextPick(mBinding.note, mBinding.noteExpandView);
            } else {
                mBinding.noteLayout.setVisibility(View.GONE);
            }

            mBinding.tvNeedFrieght.setText(entity.getAllFreight() + "元");
            mBinding.tvFreightInfo.setText(entity.getAllFreight() + "元");
            mBinding.tvMessageInfo.setText(entity.getMessagePrice());
            mBinding.nameCompany.setText(entity.getCompanyName());

            // 姓名和联系电话都没有时，不展示。
            if (entity.getSendPeople().equals("/") && entity.getSendPhone().equals("/")) {
                mBinding.rlSendInfo.setVisibility(View.GONE);
            } else {
                mBinding.title1Content.setText(entity.getSendPeople());
                if (entity.getSendPhone().equals("/")) {
                    mBinding.title2Content.setVisibility(View.GONE);
                } else {
                    mBinding.title2Content.setVisibility(View.VISIBLE);
                    mBinding.title2Content.setText(entity.getSendPhone());
                }
                mBinding.rlSendInfo.setVisibility(View.VISIBLE);
            }
            if (entity.getReceptionPeople().equals("/") && entity.getReceptionPhone().equals("/")) {
                mBinding.rlReceiveInfo.setVisibility(View.GONE);
            } else {
                mBinding.title1ReceiveContent.setText(entity.getReceptionPeople());
                if (entity.getReceptionPhone().equals("/")) {
                    mBinding.title2ReceiveContent.setVisibility(View.GONE);
                } else {
                    mBinding.title2ReceiveContent.setVisibility(View.VISIBLE);
                    mBinding.title2ReceiveContent.setText(entity.getReceptionPhone());
                }
                mBinding.rlReceiveInfo.setVisibility(View.VISIBLE);
            }

            if (mListString != null) {
                mListString.clear();
                if (null != entity.getGoodsModeName() && !entity.getGoodsModeName().isEmpty())
                    mListString.add(entity.getGoodsModeName() + (TextUtils.isEmpty(entity.getSecondGoodsTypeName()) ? "" : ("/" + entity.getSecondGoodsTypeName())));
                if (!TextUtils.isEmpty(entity.getFreightType()) && entity.getFreightType().equals("0") //一口价
                        && null != entity.getFreight() && !entity.getFreight().isEmpty() && entity.getFreightUnit() != 0) {
                    switch (entity.getFreightUnit()) {
                        case 1:
                            mListString.add(entity.getFreight() + "元/趟");
                            break;
                        case 2:
                            mListString.add(entity.getFreight() + "元/吨");
                            break;
                        case 3:
                            mListString.add(entity.getFreight() + "元/方");
                            break;
                    }
                }
                if (null != entity.getWeight() && !entity.getWeight().isEmpty() && !entity.getWeight().equals("0"))
                    mListString.add(entity.getWeight() + "吨");
                if (null != entity.getVolume() && !entity.getVolume().isEmpty() && !entity.getVolume().equals("0"))
                    mListString.add(entity.getVolume() + "方");
                if (entity.getTransportType() != null)
                    mListString.add(CargoConstant.getTransportTypeStr(entity.getTransportType()));//装车方式
                if (null != entity.getHandleTypeName() && !entity.getHandleTypeName().isEmpty())
                    mListString.add(entity.getHandleTypeName());
                mAdapter.setDatas(mListString);

                loadGoodsSourceInfo(mListString, mBinding.goodsInfoLayout);
            }

            if ((entity.getSendPeople() == null || entity.getSendPeople().equals("/")) &&
                    (entity.getSendPhone() == null || entity.getSendPhone().equals("/"))) {
                mBinding.rlSendInfo.setVisibility(View.GONE);
            } else {
                mBinding.rlSendInfo.setVisibility(View.VISIBLE);
            }
            if ((entity.getReceptionPeople() == null || entity.getReceptionPeople().equals("/")) &&
                    (entity.getReceptionPhone() == null || entity.getReceptionPhone().equals("/"))) {
                mBinding.rlReceiveInfo.setVisibility(View.GONE);
            } else {
                mBinding.rlReceiveInfo.setVisibility(View.VISIBLE);
            }

            if (mEntity.departureImg != null && !mEntity.departureImg.equals("")) {
                mListDepartureImg = Arrays.asList(mEntity.departureImg.split(","));
                mListDepartureImgNew = new ArrayList(mListDepartureImg);
            } else {
                mListDepartureImgNew = new ArrayList();
            }
            if (mEntity.receiveImg != null && !mEntity.receiveImg.equals("")) {
                mListReceiveImg = Arrays.asList(mEntity.receiveImg.split(","));
                mListReceiveImgNew = new ArrayList(mListReceiveImg);
            } else {
                mListReceiveImgNew = new ArrayList();
            }
            if (!TextUtils.isEmpty(mEntity.offlineImg)) {
                mListPayImg = Arrays.asList(mEntity.offlineImg.split(","));
            } else {
                mListPayImg = new ArrayList();
            }

            mBinding.tvStartPicture.setText("发车快照：" + mListDepartureImgNew.size() + "张照片");
            mBinding.tvReceivePicture.setText("到货快照：" + mListReceiveImgNew.size() + "张照片");
            mBinding.payProof.setText("支付凭证：" + mListPayImg.size() + "张照片");
            if (mListDepartureImgNew.size() == 0) {
                mBinding.tvStartPicture.setVisibility(View.GONE);
            } else {
                mBinding.tvStartPicture.setVisibility(View.VISIBLE);
            }
            if (mListReceiveImgNew.size() == 0) {
                mBinding.tvReceivePicture.setVisibility(View.GONE);
            } else {
                mBinding.tvReceivePicture.setVisibility(View.VISIBLE);
            }
            if (mListPayImg.size() == 0) {
                mBinding.payProof.setVisibility(View.GONE);
            } else {
                mBinding.payProof.setVisibility(View.VISIBLE);
            }

            if (entity.sendPhone == null || entity.sendPhone.isEmpty()) {
                mBinding.title2Content.setVisibility(View.GONE);
            }
            if (entity.receptionPhone == null || entity.receptionPhone.isEmpty()) {
                mBinding.title2ReceiveContent.setVisibility(View.GONE);
            }

            if (!TextUtils.isEmpty(entity.getLogo()))
                Glide.with(this).load(entity.getLogo()).apply(new RequestOptions()
                        .placeholder(R.mipmap.goods_info_default_avartor)
                        .fallback(R.mipmap.goods_info_default_avartor)
                        .error(R.mipmap.goods_info_default_avartor)).into(mBinding.ivHeaderCompany);

            List<AddressItem> items = new ArrayList<>();
            if (entity.getPlace() != null) {
                initSettingItem(items, entity.getPlace(), entity.getHandleTypeName(), entity);
                transportOrderDetailAddressAdapter = new TransportOrderDetailAddressAdapter(items, entity.place);
                transportOrderDetailAddressAdapter.SetItemOnClickListen(this);
                mBinding.rvAddress.setLayoutManager(new LinearLayoutManager(getActivity()));
                mBinding.rvAddress.setAdapter(transportOrderDetailAddressAdapter);
            }

            boolean messagePayTime = entity.messagePayTime == null || entity.messagePayTime == 0;
            boolean startTime = entity.transitTime == null || entity.transitTime == 0;
            boolean completeTime = entity.completeTime == null || entity.completeTime == 0;
            boolean freightPayTime = entity.freightPayTime == null || entity.freightPayTime == 0;
            boolean createTime = entity.createTime == null || entity.createTime == 0;
            mBinding.tvMessagePayTime.setText("信息费支付时间：" + (messagePayTime ? "/" : DateUtils.timestampToDateSecond(entity.messagePayTime)));
            mBinding.tvSendTime.setText("发车时间：" + (startTime ? "/" : DateUtils.timestampToDateSecond(entity.transitTime)));
            mBinding.tvReceiveTime.setText("到货时间：" + (completeTime ? "/" : DateUtils.timestampToDateSecond(entity.completeTime)));
            if (freightPayTime) {
                mBinding.tvFrieghtPayTime.setVisibility(View.GONE);
            } else {
                mBinding.tvFrieghtPayTime.setText("运费支付时间：" + DateUtils.timestampToDateSecond(entity.freightPayTime));
            }
            mBinding.orderTime.setText("下单时间：" + (createTime ? "/" : DateUtils.timestampToDateSecond(entity.createTime)));


            mBinding.orderNo.setText("订单编号：" + (entity.getOrderNo() == null || entity.getOrderNo().isEmpty() ? "/" : entity.getOrderNo()));

            if (entity.getmMessagePrice() == null || entity.getmMessagePrice().isEmpty() || entity.getmMessagePrice().equals("0")) {
                mBinding.llInfoCost.setVisibility(View.GONE);
                mIsHasFrieght = false;
            } else {
                mIsHasFrieght = true;
                mBinding.llInfoCost.setVisibility(View.VISIBLE);
                mBinding.tvMessagePrice.setText("实付信息费：" + (entity.getmMessagePrice() == null || entity.getmMessagePrice().isEmpty() ? "/" : NumberUtil.trim0(entity.getmMessagePrice()) + "元"));
                mBinding.messageSerialNumber.setText("信息费流水号：" + (entity.getMessageSerialNumber() == null || entity.getMessageSerialNumber().isEmpty() ? "/" : entity.getMessageSerialNumber()));
                mBinding.messageCharge.setText("信息费手续费：" + (entity.getMessageCharge() == null || entity.getMessageCharge().isEmpty() ? "0元" : entity.getMessageCharge()));
                mBinding.messagePayWay.setText("支付方式：" + (entity.getMessagePayWay() == null || entity.getMessagePayWay().isEmpty() ? "/" : entity.getMessagePayWay()));
            }

            if (entity.getFreightPrice() == null || entity.getFreightPrice().isEmpty() || entity.getFreightPrice().equals("0")) {
                mBinding.llFrieghtCost.setVisibility(View.GONE);
            } else {
                mBinding.llFrieghtCost.setVisibility(View.VISIBLE);
                mBinding.freightPrice.setText("实付运费：" + (entity.getFreightPrice() == null || entity.getFreightPrice().isEmpty() ? "/" : NumberUtil.trim0(entity.getFreightPrice()) + "元"));
                if (entity.getIsOnlinePayment() == 1) {//线上支付
                    mBinding.freightSerialNumber.setText("运费流水号：" + (entity.getFreightSerialNumber() == null || entity.getFreightSerialNumber().isEmpty() ? "/" : entity.getFreightSerialNumber()));
                    mBinding.freightCharge.setText("运费手续费：" + (entity.getFreightCharge() == null || entity.getFreightCharge().isEmpty() ? "0元" : entity.getFreightCharge()));
                    mBinding.freightPayWay.setText("支付方式：" + (entity.getFreightPayWay() == null || entity.getFreightPayWay().isEmpty() ? "/" : entity.getFreightPayWay()));
                    mBinding.freightSerialNumber.setVisibility(View.VISIBLE);
                    mBinding.freightSerialNumber.setVisibility(View.VISIBLE);
                    mBinding.freightCharge.setVisibility(View.VISIBLE);
                    mBinding.payProof.setVisibility(View.GONE);
                } else {
                    mBinding.freightPayWay.setText("支付方式：线下支付");
                    mBinding.freightSerialNumber.setVisibility(View.GONE);
                    mBinding.freightSerialNumber.setVisibility(View.GONE);
                    mBinding.freightCharge.setVisibility(View.GONE);
                    mBinding.payProof.setVisibility(View.VISIBLE);
                    mBinding.payProof.setOnClickListener(this);
                }
            }

            mBinding.tvOfflineCollection.setVisibility(View.GONE);
            if (entity.getStatus() != null)
                if (isGoodsOwner == GOODS_OWNER) {//货主
                    Drawable drawable_r = getResources().getDrawable(R.drawable.call_phone);
                    drawable_r.setBounds(0, 0, drawable_r.getMinimumWidth(), drawable_r.getMinimumHeight());
                    mBinding.carrierGroupPhone.setCompoundDrawables(null, null, drawable_r, null);
                    mBinding.phone.setCompoundDrawables(null, null, drawable_r, null);
                    switch (entity.getStatus()) {
                        case 0://待司机支付信息费
                            mBinding.actionBar.setTitle("待货主确认");
                            mBinding.tvMessagePayState.setText("支付中");
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.tvOfflineCollection.setVisibility(View.GONE);
                            isViewTrack = true;
                            mBinding.ivUnfold.setVisibility(View.GONE);
                            mBinding.tvUnfoldMore.setVisibility(View.GONE);
                            break;
                        case 1://待货主确认
                            mBinding.actionBar.setTitle("待货主确认");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.daiqueren);
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.llSend.setVisibility(View.GONE);
                            mBinding.llReceive.setVisibility(View.GONE);
                            if (UserOperating.getInstance().isPersonal()) {
                                mBinding.tvConfirmReceive.setText("确认订单");
                                mBinding.tvConfirmReceive.setVisibility(View.VISIBLE);
                            } else {
                                mBinding.tvConfirmReceive.setText("确认订单");
                                mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            }
//                        mBinding.location.setVisibility(View.GONE);
                            mBinding.ivUnfold.setVisibility(mIsHasFrieght ? View.VISIBLE : View.GONE);
                            mBinding.tvUnfoldMore.setVisibility(mIsHasFrieght ? View.VISIBLE : View.GONE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.GONE);

                            break;
                        case 2://待司机发车
                            mBinding.actionBar.setTitle("待司机发车");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.daifache);
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.llSend.setVisibility(View.GONE);
                            mBinding.llReceive.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
//                        mBinding.location.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(mIsHasFrieght ? View.VISIBLE : View.GONE);
                            mBinding.tvUnfoldMore.setVisibility(mIsHasFrieght ? View.VISIBLE : View.GONE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.GONE);
                            break;
                        case 3://运输中
                            mBinding.actionBar.setTitle("运输中");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.yunshuzhong);
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.llSend.setVisibility(View.VISIBLE);
                            mBinding.llReceive.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            mBinding.ivUnfold.setVisibility(View.VISIBLE);
                            mBinding.tvUnfoldMore.setVisibility(View.VISIBLE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.VISIBLE);
                            break;
                        case 4://已完成
                            mBinding.actionBar.setTitle("已完成");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.yiwancheng);
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.VISIBLE);
                            mBinding.llFrieghtCost.setVisibility(View.VISIBLE);
                            mBinding.llSend.setVisibility(View.VISIBLE);
                            mBinding.llReceive.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(View.VISIBLE);
                            mBinding.tvUnfoldMore.setVisibility(View.VISIBLE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.VISIBLE);
                            break;
                        case 5://已取消
                            mBinding.actionBar.setTitle("已取消");
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.tvMessagePayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.llInfoCost.setVisibility(View.GONE);
                            mBinding.llSend.setVisibility(View.GONE);
                            mBinding.llReceive.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            mBinding.cancelTime.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(View.VISIBLE);
                            mBinding.tvUnfoldMore.setVisibility(View.VISIBLE);
                            //不需要展示轨迹地图
                            isViewTrack = false;
                            break;
                        case 6://待货主付款
                            mBinding.actionBar.setTitle("待支付运费");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.daizhifu);
                            mBinding.llNeedFrieght.setVisibility(View.VISIBLE);
                            mBinding.tvNeedFrieghtKey.setText("待支付运费");
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setText("支付运费");
                            mBinding.llSend.setVisibility(View.VISIBLE);
                            mBinding.llReceive.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(View.VISIBLE);
                            mBinding.tvUnfoldMore.setVisibility(View.VISIBLE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.VISIBLE);
                            break;
                    }
                } else {//车主
                    mBinding.carrierGroupPhone.setCompoundDrawables(null, null, null, null);
                    mBinding.phone.setCompoundDrawables(null, null, null, null);
                    switch (entity.getStatus()) {
                        case 0://待司机支付信息费
                            mBinding.actionBar.setTitle("待货主确认");
                            mBinding.tvMessagePayState.setText("支付中");
                            mBinding.tvConfirmReceive.setText("支付信息费");
                            mBinding.tvConfirmReceive.setVisibility(UserOperating.getInstance().isCompany() ? View.GONE : View.VISIBLE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.tvOfflineCollection.setVisibility(View.GONE);
                            isViewTrack = true;
                            mBinding.ivUnfold.setVisibility(View.GONE);
                            mBinding.tvUnfoldMore.setVisibility(View.GONE);
                            break;
                        case 1://待货主确认
                            mBinding.actionBar.setTitle("待货主确认");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.daiqueren);
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.llSend.setVisibility(View.GONE);
                            mBinding.llReceive.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            mBinding.ivUnfold.setVisibility(mIsHasFrieght ? View.VISIBLE : View.GONE);
                            mBinding.tvUnfoldMore.setVisibility(mIsHasFrieght ? View.VISIBLE : View.GONE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.GONE);
                            break;
                        case 2://待司机发车
                            mBinding.actionBar.setTitle("待发车");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.daifache);
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.llSend.setVisibility(View.GONE);
                            mBinding.llReceive.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setText("确认发车");
                            mBinding.tvConfirmReceive.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(mIsHasFrieght ? View.VISIBLE : View.GONE);
                            mBinding.tvUnfoldMore.setVisibility(mIsHasFrieght ? View.VISIBLE : View.GONE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.GONE);
                            break;
                        case 3://运输中
                            mBinding.actionBar.setTitle("运输中");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.yunshuzhong);
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.llSend.setVisibility(View.VISIBLE);
                            mBinding.llReceive.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setText("确认送达");
                            mBinding.tvConfirmReceive.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(View.VISIBLE);
                            mBinding.tvUnfoldMore.setVisibility(View.VISIBLE);
                            mBinding.mapLayout.setVerticalGravity(View.VISIBLE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.VISIBLE);
                            break;
                        case 4://已完成
                            mBinding.actionBar.setTitle("已完成");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.yiwancheng);
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.VISIBLE);
                            mBinding.llFrieghtCost.setVisibility(View.VISIBLE);
                            mBinding.llSend.setVisibility(View.VISIBLE);
                            mBinding.llReceive.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(View.VISIBLE);
                            mBinding.tvUnfoldMore.setVisibility(View.VISIBLE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.VISIBLE);
                            break;
                        case 5://已取消
                            mBinding.actionBar.setTitle("已取消");
                            mBinding.llNeedFrieght.setVisibility(View.GONE);
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.tvMessagePayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.llInfoCost.setVisibility(View.GONE);
                            mBinding.llSend.setVisibility(View.GONE);
                            mBinding.llReceive.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            mBinding.cancelTime.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(View.VISIBLE);
                            mBinding.tvUnfoldMore.setVisibility(View.VISIBLE);
                            //不需要展示轨迹地图
                            isViewTrack = false;
                            break;
                        case 6://待货主付款
                            mBinding.actionBar.setTitle("待货主支付运费");
                            mBinding.tvMessagePayState.setText("已支付");
                            mBinding.llOrderStatus.setBackgroundResource(R.mipmap.daizhifu);
                            mBinding.llNeedFrieght.setVisibility(View.VISIBLE);
                            mBinding.tvNeedFrieghtKey.setText("需收运费");
                            mBinding.tvFreightPayState.setVisibility(View.GONE);
                            mBinding.llFrieghtCost.setVisibility(View.GONE);
                            mBinding.tvConfirmReceive.setText("收款二维码");
                            mBinding.tvConfirmReceive.setVisibility(View.GONE);
                            mBinding.tvOfflineCollection.setVisibility(View.VISIBLE);
                            mBinding.tvOfflineCollection.setOnClickListener(this);
                            mBinding.llSend.setVisibility(View.VISIBLE);
                            mBinding.llReceive.setVisibility(View.VISIBLE);
                            mBinding.ivUnfold.setVisibility(View.VISIBLE);
                            mBinding.tvUnfoldMore.setVisibility(View.VISIBLE);
                            mBinding.tvOnline.setVisibility(View.VISIBLE);
                            //需要展示轨迹地图
                            isViewTrack = true;
                            mBinding.viewLogisticsDetails.setVisibility(View.VISIBLE);
                            break;
                    }
                }

            //展示物流地图信息
            if (aMap != null && isViewTrack) {
                viewModel.loadMapInfo(mEntity, aMap);
            }
        }
    }

    private List<SingleItemEntity> getCustomList(TransportOrderEntity mOrderEntity) {
        mCustomList.clear();
        if (mOrderEntity != null && mOrderEntity.getAddField() != null && mOrderEntity.getAddField().size() > 0) {
            for (int i = 0; i < mOrderEntity.getAddField().size(); i++) {
                mCustomList.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, mOrderEntity.getAddField().get(i).getKey(), mOrderEntity.getAddField().get(i).getValue()));
            }
        }
        return mCustomList;
    }

    /**
     * 装载货源信息
     */
    private void loadGoodsSourceInfo(List<String> strings, WrapLinearLayout lay_gallery) {
        lay_gallery.removeAllViews();
        LayoutInflater mInflater = LayoutInflater.from(getActivity());
        if (strings != null && strings.size() != 0) {
            for (int i = 0; i < strings.size(); i++) {
                final View view = mInflater.inflate(R.layout.item_goods_transport_info_02, lay_gallery, false);
                final TextView tv_info = view.findViewById(R.id.tv_info);
                tv_info.setText(strings.get(i));
                lay_gallery.addView(view);
            }
        }
    }

    /**
     * 初始化功能列表
     */
    public void initSettingItem(List<AddressItem> list, OperateGoodsSourcePlaceVO mgoodsSourcePkace, String handleTypeNo, TransportOrderEntity entity) {
        if (list == null) return;
        list.clear();
        if ("一装一卸".equals(handleTypeNo)) {//一装一卸
            list.add(new AddressItem(mgoodsSourcePkace.getProvinceName() + "  " + mgoodsSourcePkace.getCityName() + "  " + mgoodsSourcePkace.getDistrictName(), mgoodsSourcePkace.getDetailAddress(), mgoodsSourcePkace.getFirstDistance(), true, R.mipmap.icon_load_goods, handleTypeNo, 0,
                    entity.getShipmentTime(), entity.getStartPointTime(), entity.getShipmentEndTime(), entity.getEndPointTime(), 0));
            list.add(new AddressItem(mgoodsSourcePkace.getDestProvinceName() + "  " + mgoodsSourcePkace.getDestCityName() + "  " + mgoodsSourcePkace.getDestDistrictName(), mgoodsSourcePkace.getDestDetailAddress(), null, false, R.mipmap.icon_unload_goods, handleTypeNo, 1,
                    0, 0, entity.getArrivalTime()));
        } else if ("一装两卸".equals(handleTypeNo)) {//一装两卸
            list.add(new AddressItem(mgoodsSourcePkace.getProvinceName() + "  " + mgoodsSourcePkace.getCityName() + "  " + mgoodsSourcePkace.getDistrictName(), mgoodsSourcePkace.getDetailAddress(), mgoodsSourcePkace.getFirstDistance(), true, R.mipmap.icon_load_goods, handleTypeNo, 0,
                    entity.getShipmentTime(), entity.getStartPointTime(), entity.getShipmentEndTime(), entity.getEndPointTime(), 0));
            list.add(new AddressItem(mgoodsSourcePkace.getViaDestProvinceName() + "  " + mgoodsSourcePkace.getViaDestCityName() + "  " + mgoodsSourcePkace.getViaDestDistrictName(), mgoodsSourcePkace.getViaDestDetailAddress(), mgoodsSourcePkace.getSecondDistance(), true, R.mipmap.icon_unload_one, handleTypeNo, 1));
            list.add(new AddressItem(mgoodsSourcePkace.getDestProvinceName() + "  " + mgoodsSourcePkace.getDestCityName() + "  " + mgoodsSourcePkace.getDestDistrictName(), mgoodsSourcePkace.getDestDetailAddress(), null, false, R.mipmap.icon_unload_two, handleTypeNo, 2,
                    0, 0, entity.getArrivalTime()));
        } else if ("两装一卸".equals(handleTypeNo)) {//两装一卸
            list.add(new AddressItem(mgoodsSourcePkace.getProvinceName() + "  " + mgoodsSourcePkace.getCityName() + "  " + mgoodsSourcePkace.getDistrictName(), mgoodsSourcePkace.getDetailAddress(), mgoodsSourcePkace.getFirstDistance(), true, R.mipmap.icon_load_one, handleTypeNo, 0,
                    entity.getShipmentTime(), entity.getStartPointTime(), entity.getShipmentEndTime(), entity.getEndPointTime(), 0));
            list.add(new AddressItem(mgoodsSourcePkace.getViaSendProvinceName() + "  " + mgoodsSourcePkace.getViaSendCityName() + "  " + mgoodsSourcePkace.getViaSendDistrictName(), mgoodsSourcePkace.getViaSendDetailAddress(), mgoodsSourcePkace.getSecondDistance(), true, R.mipmap.icon_load_two, handleTypeNo, 1));
            list.add(new AddressItem(mgoodsSourcePkace.getDestProvinceName() + "  " + mgoodsSourcePkace.getDestCityName() + "  " + mgoodsSourcePkace.getDestDistrictName(), mgoodsSourcePkace.getDestDetailAddress(), null, false, R.mipmap.icon_unload_goods, handleTypeNo, 2,
                    0, 0, entity.getArrivalTime()));
        } else if ("两装两卸".equals(handleTypeNo)) {
            list.add(new AddressItem(mgoodsSourcePkace.getProvinceName() + "  " + mgoodsSourcePkace.getCityName() + "  " + mgoodsSourcePkace.getDistrictName(), mgoodsSourcePkace.getDetailAddress(), mgoodsSourcePkace.getFirstDistance(), true, R.mipmap.icon_load_one, handleTypeNo, 0,
                    entity.getShipmentTime(), entity.getStartPointTime(), entity.getShipmentEndTime(), entity.getEndPointTime(), 0));
            list.add(new AddressItem(mgoodsSourcePkace.getViaSendProvinceName() + "  " + mgoodsSourcePkace.getViaSendCityName() + "  " + mgoodsSourcePkace.getViaSendDistrictName(), mgoodsSourcePkace.getViaSendDetailAddress(), mgoodsSourcePkace.getSecondDistance(), true, R.mipmap.icon_load_two, handleTypeNo, 1));
            list.add(new AddressItem(mgoodsSourcePkace.getViaDestProvinceName() + "  " + mgoodsSourcePkace.getViaDestCityName() + "  " + mgoodsSourcePkace.getViaDestDistrictName(), mgoodsSourcePkace.getViaDestDetailAddress(), mgoodsSourcePkace.getThirdDistance(), true, R.mipmap.icon_unload_one, handleTypeNo, 2));
            list.add(new AddressItem(mgoodsSourcePkace.getDestProvinceName() + "  " + mgoodsSourcePkace.getDestCityName() + "  " + mgoodsSourcePkace.getDestDistrictName(), mgoodsSourcePkace.getDestDetailAddress(), null, false, R.mipmap.icon_unload_two, handleTypeNo, 3,
                    0, 0, entity.getArrivalTime()));
        }
    }

    @Override
    public void onItemClick(OperateGoodsSourcePlaceVO place, String typeNo, int position) {
        switch (typeNo) {
            case "一装一卸":
                LoadingAndUnloadingPlaceActivity.start(this, position, "11", place);
                break;
            case "一装两卸":
                LoadingAndUnloadingPlaceActivity.start(this, position, "12", place);
                break;
            case "两装一卸":
                LoadingAndUnloadingPlaceActivity.start(this, position, "21", place);
                break;
            case "两装两卸":
                LoadingAndUnloadingPlaceActivity.start(this, position, "22", place);
                break;
        }
    }

    @Override
    public void OnWholeItemClick(View view) {
        switch (view.getId()) {
            case R.id.itv_requirement://货运要求与责任约定
                if (null != mEntity)
                    OrderRequireInfoActivity.start(this, mEntity, isGoodsOwner == GOODS_OWNER);
                break;
            case R.id.itv_payment_appointment://付款约定与开票信息
                if (null != mEntity)
                    TransportInvoiceInfoActivity.start(this, mEntity);
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getCode(ZMessageEvent event) {
        switch (event.code) {
            case Constants.EVENT_REFRESH:
                viewModel.getDetailData(this, mMap);
                break;

            case Constants.EVENT_PAY_SUCCESS:
                finish();
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(LogisticsEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_SURE_START_TRANSPORT_SUCCESS) {
            finish();
        }
    }


    /**
     * 信息费支付倒计时
     */
    class PayTimer extends CountDownTimer {

        private SpannableString countSpan;
        private String contentText;

        public PayTimer(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            int minutes = (int) (millisUntilFinished / (1000 * 60));
            int seconds = (int) ((millisUntilFinished / 1000) % 60);
            String minutesStr = "";
            if (minutes > 0) {
                minutesStr = minutes + "分";
            }
            if (isGoodsOwner == GOODS_OWNER) {
                contentText = "请等待承运方支付信息费。剩余支付时间 " + minutesStr + seconds + "秒";
                countSpan = new SpannableString(contentText);
                countSpan.setSpan(new StyleSpan(Typeface.BOLD), 18, contentText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                mBinding.payMessageFeeCountDown.setGravity(Gravity.CENTER);
            } else {
                if (mEntity != null && mEntity.getQuoteOfferType() != null && mEntity.getQuoteOfferType() == 1) {
                    contentText = "信息费支付中，请联系财务至资金中心-待付订单完成支付。剩余支付时间 " + minutesStr + seconds + "秒";
                    countSpan = new SpannableString(contentText);
                    countSpan.setSpan(new StyleSpan(Typeface.BOLD), 33, contentText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    mBinding.payMessageFeeCountDown.setGravity(Gravity.LEFT);
                } else {
                    contentText = "信息费支付中,剩余支付时间 " + minutesStr + seconds + "秒";
                    countSpan = new SpannableString(contentText);
                    countSpan.setSpan(new StyleSpan(Typeface.BOLD), 13, contentText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    mBinding.payMessageFeeCountDown.setGravity(Gravity.CENTER);
                }
            }
            mBinding.payMessageFeeCountDown.setText(countSpan);
        }

        @Override
        public void onFinish() {
            EventBus.getDefault().post(LogisticsEvent.make().setMessageTag(EventConstant.EVENT_REFRESH_TRANSPORT_ORDER_LIST));
            mBinding.countDownLayout.setVisibility(View.GONE);
            viewModel.ldTimeout.postValue(true);
        }
    }

    /**
     * 支付超时提示弹窗
     */
    private void showTimeoutDialog() {
        //避免重复弹窗
        if (!isTimeoutShowed) {
            new RoundDialog.Builder(TransportOrderDetailOwnerActivity.this)
                    .title("提示")
                    .content("订单已超时，无法支付。")
                    .singleBtn(true)
                    .confirm("确定")
                    .cancelable(false)
                    .confirmCallback(view -> {
                        TransportOrderDetailOwnerActivity.this.finish();
                    })
                    .show();
            isTimeoutShowed = true;
        }

    }
}
